package com.kuang.controller;

import com.kuang.pojo.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**环境测试
 * @author FHL
 */
@RestController
//@RestController屏蔽了视图解析器，不跳转页面
public class HelloController {
    @RequestMapping("/t1")
    public String test(){
return "hello";
    }
    @RequestMapping("/a1")
    public void a1(String name, HttpServletResponse response) throws IOException {
        System.out.println("a1:param=>"+name);
        if ("kuangshen".equals(name)){
            response.getWriter().print("true");
        }else {
            response.getWriter().print("false");
        }
    }
    @RequestMapping("/a2")
    public List<User> a2(){
        List<User> list=new ArrayList<User>();
        list.add(new User("李玉",11,"男"));
        list.add(new User("喻于义",10,"男"));
        list.add(new User("姚淑儿",9,"女"));
        return list;
    }
    @RequestMapping("/a3")
    public String a3(String name,String pwd){
        String msg="";
        if (name!=null){
            //这些数据库在实际应用中是在数据库中查找的
            if ("admin".equals(name)){
                msg="OK！";
            }else {
                msg="用户名不存在！";
            }
        }
        if (pwd!=null){
            if ("123456".equals(pwd)){
                msg="OK！";
            }else {
                msg="密码错误！";
            }
        }
        return msg;
    }

}
